package hot100;

public class setZeroes3 {
    public void setZeroes(int[][] matrix) {
        //使用行 列两个数组记录哪行和那列要变为0
        int n = matrix.length;
        int m = matrix[0].length;
        boolean[] row =  new boolean[n];
        boolean[] col = new boolean[m];

        for(int i = 0;i < n ;i++) {
            for (int j = 0 ;j < m ;j++) {
                if(matrix[i][j] == 0) {
                    row[i] = col[j] = true;
                }
            }
        }

        //开始重置
        for(int i = 0;i < n ;i++) {
            for (int j = 0 ;j < m ;j++) {
                if(row[i]||col[j]) {
                    matrix[i][j] = 0;
                }
            }
        }

    }
}
